<?php

use app\config\Db;
use Core\Result\Result;
use Core\Common\Common;

/**
 * 首页活动商品
 */

function activeGoodsList($data)
{
    $id = $data['id'];
    $page = $data['page'];
    $limit = $data['limit'];
    $db = new Db();
    $field = 'goods_id,category_id,shop_id,name,goods_type,title,old_price,sell_price,game_points,img_id,hits,sales_volume,unreal_sales_volume,create_time';
    $order = "order by sort desc,unreal_sales_volume desc,sales_volume desc,g.create_time desc";
    $goodsListSql = "select $field from `ysmz_active_goods` as a inner join `ysmz_shop_goods` as g on a.gid = g.goods_id where aid = $id and a.state = 1 and is_delete=0 and is_adopt=1 and is_top=1 $order limit $page,$limit";
    $goodsList = $db->query($goodsListSql);
    foreach ($goodsList as $k => $v) {
        $imgSql = "select file_id,storage,`domain`,file_path from `ysmz_file` where file_id =$v[img_id]";
        $file = $db->find($imgSql);
        $goodsList[$k]['img_url'] = Common::fileUrl($file);
    }
    Result::success($goodsList);
}
/**
 * 商城活动 TODO
 * @param
 * @return void
 */
function shopActiveList()
{
    $db = new Db();
    $data = $db->query("select id,img,`name`,`identificationName`,`remarks` from ysmz_active where state=1 and type = 2");
    Result::success($data);
}